<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '':'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    :label-position="config.layout.shrink ? 'top' : 'right'"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                    <FormItem  :label="t('store.order.store_id')" type="remoteSelect" v-model="baTable.form.items!.store_id" prop="store_id" :input-attr="{ pk: 'ba_store_store.id', field: 'name', remoteUrl: '/admin/store.Store/index' }" :placeholder="t('Please select field', { field: t('store.order.store_id') })" />
                    <FormItem  :label="t('store.order.order_status')" type="radio" v-model="baTable.form.items!.order_status" prop="order_status" :input-attr="{ content: { '10': t('store.order.order_status 10'), '20': t('store.order.order_status 20'), '21': t('store.order.order_status 21'), '30': t('store.order.order_status 30'), '100': t('store.order.order_status 100'), '200': t('store.order.order_status 200'), '250': t('store.order.order_status 250') } }" :placeholder="t('Please select field', { field: t('store.order.order_status') })" />
                    <FormItem  :label="t('store.order.product_price')" type="number" prop="product_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.product_price" :placeholder="t('Please input field', { field: t('store.order.product_price') })" />
                    <FormItem  :label="t('store.order.order_price')" type="number" prop="order_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.order_price" :placeholder="t('Please input field', { field: t('store.order.order_price') })" />
                    <el-descriptions :title="$t('store.order.product_infos')" class="info-box-head"> </el-descriptions>
                    <el-table :data="baTable.form.items!.product_infos" class="info-box-table" border>
                        <el-table-column
                            :label="$t('商品标题')"
                            prop="title"
                            align="center"
                            min-width="200"
                        ></el-table-column>
                        <el-table-column :label="$t('商品编码')" prop="sku_id" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('图片')" align="center" min-width="130">
                            <template #default="{ row }">
                                <el-image
                                    :src="fullUrl(row.thumb_img)"
                                    :preview-src-list="arrayFullUrl([row.thumb_img])"
                                    :preview-teleported="true"
                                    class="info-box-table-img"
                                />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('售卖单价')" :prop='sale_price' align="center" min-width="130">
                            <template #default="scope">
                                <span>
                                    <span>{{ scope.row.sale_price/100 }}</span>
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('sku数量')" prop="sku_cnt" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('sku属性')" prop='sku_attrs' align="center" min-width="130"></el-table-column>
                    </el-table>
                    <br><br>
                    <FormItem  :label="t('store.order.freight')" type="number" prop="freight" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.freight" :placeholder="t('Please input field', { field: t('store.order.freight') })" />
                    <FormItem  :label="t('store.order.discounted_price')" type="number" prop="discounted_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.discounted_price" :placeholder="t('Please input field', { field: t('store.order.discounted_price') })" />
                    <FormItem  :label="t('store.order.isdiscounted')" type="radio" v-model="baTable.form.items!.isdiscounted" prop="isdiscounted" :input-attr="{ content: { '1': t('store.order.isdiscounted 1'), '2': t('store.order.isdiscounted 2') } }" :placeholder="t('Please select field', { field: t('store.order.isdiscounted') })" />
                    <FormItem  :label="t('store.order.user_name')" type="string" v-model="baTable.form.items!.user_name" prop="user_name" :placeholder="t('Please input field', { field: t('store.order.user_name') })" />
                    <FormItem  :label="t('store.order.postal_code')" type="string" v-model="baTable.form.items!.postal_code" prop="postal_code" :placeholder="t('Please input field', { field: t('store.order.postal_code') })" />
                    <FormItem  :label="t('store.order.province_name')" type="string" v-model="baTable.form.items!.province_name" prop="province_name" :placeholder="t('Please input field', { field: t('store.order.province_name') })" />
                    <FormItem  :label="t('store.order.city_name')" type="string" v-model="baTable.form.items!.city_name" prop="city_name" :placeholder="t('Please input field', { field: t('store.order.city_name') })" />
                    <FormItem  :label="t('store.order.county_name')" type="string" v-model="baTable.form.items!.county_name" prop="county_name" :placeholder="t('Please input field', { field: t('store.order.county_name') })" />
                    <FormItem  :label="t('store.order.detail_info')" type="string" v-model="baTable.form.items!.detail_info" prop="detail_info" :placeholder="t('Please input field', { field: t('store.order.detail_info') })" />
                    <FormItem  :label="t('store.order.tel_number')" type="string" v-model="baTable.form.items!.tel_number" prop="tel_number" :placeholder="t('Please input field', { field: t('store.order.tel_number') })" />
                    <el-descriptions :title="$t('store.order.delivery_product_info')" class="info-box-head"> </el-descriptions>
                    <el-table :data="baTable.form.items!.delivery_product_info" class="info-box-table" border>
                        <el-table-column
                            :label="$t('快递单号')"
                            prop="waybill_id"
                            align="center"
                            min-width="200"
                        ></el-table-column>
                        <el-table-column :label="$t('快递公司编码')" prop="delivery_id" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('快递公司名称')" prop="delivery_name" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('发货时间')" prop='delivery_time' align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('包裹中商品信息')" prop='product_infos' align="center" min-width="130"></el-table-column>
                    </el-table>
                    <br><br>

                    <FormItem  :label="t('store.order.ship_done_time')" type="datetime" v-model="baTable.form.items!.ship_done_time" prop="ship_done_time" :placeholder="t('Please select field', { field: t('store.order.ship_done_time') })" />
                    <FormItem  :label="t('store.order.deliver_method')" type="radio" v-model="baTable.form.items!.deliver_method" prop="deliver_method" :input-attr="{ content: { '0': t('store.order.deliver_method 0'), '1/3': t('store.order.deliver_method 1/3') } }" :placeholder="t('Please select field', { field: t('store.order.deliver_method') })" />
                    <FormItem  :label="t('store.order.user_coupon_id')" type="string" v-model="baTable.form.items!.user_coupon_id" prop="user_coupon_id" :placeholder="t('Please input field', { field: t('store.order.user_coupon_id') })" />
                    <FormItem  :label="t('store.order.customer_notes')" type="string" v-model="baTable.form.items!.customer_notes" prop="customer_notes" :placeholder="t('Please input field', { field: t('store.order.customer_notes') })" />
                    <FormItem  :label="t('store.order.merchant_notes')" type="string" v-model="baTable.form.items!.merchant_notes" prop="merchant_notes" :placeholder="t('Please input field', { field: t('store.order.merchant_notes') })" />
                    <FormItem  :label="t('store.order.finder_id')" type="string" v-model="baTable.form.items!.finder_id" prop="finder_id" :placeholder="t('Please input field', { field: t('store.order.finder_id') })" />
                    <FormItem  :label="t('store.order.live_id')" type="string" v-model="baTable.form.items!.live_id" prop="live_id" :placeholder="t('Please input field', { field: t('store.order.live_id') })" />
                    <FormItem  :label="t('store.order.order_scene')" type="string" v-model="baTable.form.items!.order_scene" prop="order_scene" :placeholder="t('Please input field', { field: t('store.order.order_scene') })" />
                    <el-descriptions :title="$t('store.order.sharer_info')" border class="info-box-head">
                        <el-descriptions-item :label="$t('分享员openid')" min-width="130">
                            {{ baTable.form.items!.sharer_info.sharer_openid }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('分享员unionid')" min-width="130">
                            {{ baTable.form.items!.sharer_info.sharer_unionid }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('分享员类型')" min-width="130">
                            {{ baTable.form.items!.sharer_info.sharer_type }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('分享场景')" min-width="130">
                            {{ baTable.form.items!.sharer_info.share_scene }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('是否已经解析完成')" min-width="130">
                            {{ baTable.form.items!.sharer_info.handling_progress }}
                        </el-descriptions-item>
                    </el-descriptions>
                    <br><br>

                    <FormItem  :label="t('store.order.commission_fee')" type="number" prop="commission_fee" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.commission_fee" :placeholder="t('Please input field', { field: t('store.order.commission_fee') })" />
                    <FormItem  :label="t('store.order.predict_commission_fee')" type="number" prop="predict_commission_fee" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.predict_commission_fee" :placeholder="t('Please input field', { field: t('store.order.predict_commission_fee') })" />
                    <el-descriptions :title="$t('store.order.pay_info')" border class="info-box-head">
                        <el-descriptions-item :label="$t('预支付id')" min-width="130">
                            {{ baTable.form.items!.pay_info.prepay_id }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('预支付时间')" min-width="130">
                            {{ baTable.form.items!.pay_info.prepay_time }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('支付时间')" min-width="130">
                            {{ baTable.form.items!.pay_info.pay_time }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('支付订单号')" min-width="130">
                            {{ baTable.form.items!.pay_info.transaction_id }}
                        </el-descriptions-item>
                        <el-descriptions-item :label="$t('支付方式')" min-width="130">
                            {{ baTable.form.items!.pay_info.payment_method }}
                        </el-descriptions-item>
                    </el-descriptions>
                    <br><br>

                    <el-descriptions :title="$t('store.order.sku_sharer_infos')" class="info-box-head"> </el-descriptions>
                    <el-table :data="baTable.form.items!.sku_sharer_infos" class="info-box-table" border>
                        <el-table-column
                            :label="$t('分享员openid')"
                            prop="sharer_openid"
                            align="center"
                            min-width="200"
                        ></el-table-column>
                        <el-table-column :label="$t('分享员unionid')" prop="sharer_unionid" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('分享员类型')" prop="sharer_type" align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('分享场景')" prop='share_scene' align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('商品skuid')" prop='sku_id' align="center" min-width="130"></el-table-column>
                        <el-table-column :label="$t('是否来自企微分享')" prop='from_wecom' align="center" min-width="130"></el-table-column>
                    </el-table>
                    <br><br>


                    <FormItem readonly="readonly" :label="t('store.order.openid')" type="string" v-model="baTable.form.items!.openid" prop="openid" :placeholder="t('Please input field', { field: t('store.order.openid') })" />
                    <FormItem  :label="t('store.order.create_time')" type="string" v-model="baTable.form.items!.create_time" prop="create_time" :placeholder="t('Please select field', { field: t('store.order.create_time') })" />
                    <FormItem  :label="t('store.order.update_time')" type="string" v-model="baTable.form.items!.update_time" prop="update_time" :placeholder="t('Please select field', { field: t('store.order.update_time') })" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
<!--                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">-->
<!--                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}-->
<!--                </el-button>-->
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance, FormItemRule } from 'element-plus'
import { inject, reactive, ref,computed } from 'vue'
import { useI18n } from 'vue-i18n'
import FormItem from '/@/components/formItem/index.vue'
import { useConfig } from '/@/stores/config'
import type baTableClass from '/@/utils/baTable'
import { buildValidatorData } from '/@/utils/validate'
import { arrayFullUrl, fullUrl } from '/@/utils/common'
import { showDeliveryButton, showCancelButton, getStatusType, showCloseButton } from '/@/views/backend/shop/order/order/index'
import ExpressDialog from './expressDialog.vue'
import { getExpressTrack } from '/@/api/backend/shop/order/order'
import { orderStatusEnum } from '/@/views/backend/shop/order/order/index'


const config = useConfig()
const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    ship_done_time: [buildValidatorData({ name: 'date', title: t('store.order.ship_done_time') })],
    create_time: [buildValidatorData({ name: 'date', title: t('store.order.create_time') })],
    update_time: [buildValidatorData({ name: 'date', title: t('store.order.update_time') })],
})

const saleprice = (sale_price) => {
console.log('11123123123123',sale_price)
}

</script>

<style scoped lang="scss"></style>
